package com.example.websocketdemo.controller;

import com.example.websocketdemo.pojo.WiselyMessageDto;
import com.example.websocketdemo.pojo.WiselyMessageVo;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

/**
 * @author ljw
 * @description
 * @date 2021/12/9 7:37
 */
@Controller
public class WsController {

    /**
     * 接收浏览器消息并且广播出去
     * @param wiselyMessageVo 浏览器消息
     * @author ljw
     * @date 2021/12/9 7:40
     */
    //类似@RequestMapping 映射 /welcome 这个地址,从浏览器接收信息
    @MessageMapping("/welcome")
    @SendTo("/topic/getResponse") //广播出去，对订阅了 @SendTo 中的路径的浏览器发送消息
    public WiselyMessageDto sendMsgToOthers(WiselyMessageVo wiselyMessageVo) throws Exception{
        Thread.sleep(3000);
        return new WiselyMessageDto("后端广播的消息："+wiselyMessageVo.getName());
    }
}
